home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / DBMSUTIL.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  38.8 KB  |  890 lines

  1. rem 
  2. rem $Header: dbmsutil.sql 7020200.5 95/03/29 18:10:05 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      dbmsutil.sql - packages of various utility procedures
  7. Rem    DESCRIPTION
  8. Rem      This file contains various packages:
  9. Rem         dbms_transaction      - transaction commands
  10. Rem         dbms_session      - alter session commands
  11. Rem         dbms_ddl          - ddl commands
  12. Rem         dbms_utility      - helpful utilities
  13. Rem         dbms_application_info - application information registration
  14. Rem         dbms_system           - database system level commands
  15. Rem         dbms_space            - segment space analysis
  16. Rem    RETURNS
  17. Rem 
  18. Rem    NOTES
  19. Rem      The procedural option is needed to use these facilities.
  20. Rem
  21. Rem      All of the packages below run with the privileges of calling user,
  22. Rem      rather than the package owner ('sys').
  23. Rem
  24. Rem      Procedure 'dbms_ddl.alter_compile' and 'dbms_ddl.analyze_object
  25. Rem      commit the current transaction, perform the compilation, and 
  26. Rem      then commit again.
  27. Rem 
  28. Rem      The dbms_utility package is run-as-caller (psdicd.c) only for
  29. Rem      its name_resolve, compile_schema and analyze_schema
  30. Rem      procedures.  This package is not run-as-caller
  31. Rem      w.r.t. SQL (psdpgi.c) so that the SQL works correctly (runs as
  32. Rem      SYS).  The privileges are checked via dbms_ddl.
  33. Rem
  34. Rem    MODIFIED   (MM/DD/YY)
  35. Rem     bhirano    12/23/94 -  merge changes from branch 1.41.710.6
  36. Rem     jloaiza    09/06/94 -  dbms_registration -> dbms_application_info
  37. Rem     atsukerm   06/20/94 -  adding DBMS_SPACE package
  38. Rem     jloaiza    06/08/94 -  change name to dbms_registration
  39. Rem     jloaiza    04/07/94 -  add dbms_application
  40. Rem     dsdaniel   04/07/94 -  merge changes from branch 1.41.710.4
  41. Rem     wmaimone   04/07/94 -  merge changes from branch 1.41.710.5
  42. Rem     adowning   03/29/94 -  merge changes from branch 1.41.710.3
  43. Rem     wmaimone   02/07/94 -  add set close_cached_open_cursors to dbms_sessio
  44. Rem     dsdaniel   02/04/94 -  dbms_util.port_string icd
  45. Rem     adowning   02/02/94 -  split file into public / private binary files
  46. Rem     rjenkins   11/17/93 -  merge changes from branch 1.41.710.2
  47. Rem     rjenkins   10/20/93 -  merge changes from branch 1.41.710.1
  48. Rem     rjenkins   10/28/93 -  make comma_to_table more consistent
  49. Rem     rjenkins   10/12/93 -  adding comma_to_table
  50. Rem     rjenkins   09/03/93 -  adding name_parse
  51. Rem     hjakobss   07/15/93 -  bug 170473
  52. Rem     hjakobss   07/13/93 -  bug 169577
  53. Rem     dsdaniel   03/12/93 -  local_tid, step_id functions for replication  
  54. Rem     mmoore     01/11/93 -  merge changes from branch 1.37.312.1 
  55. Rem     mmoore     01/05/93 - #(145287) add another exception for discrete mode
  56. Rem     mmoore     12/11/92 -  disable set_role in stored procs 
  57. Rem     rkooi      11/24/92 -  fixes per Peter 
  58. Rem     rkooi      11/21/92 -  get rid of error argument to name_resolve 
  59. Rem     tpystyne   11/20/92 -  fix compile_all and analyze_schema 
  60. Rem     rkooi      11/16/92 -  fix set_label 
  61. Rem     rkooi      11/16/92 -  fix comments 
  62. Rem     rkooi      11/13/92 -  add name_res procedure 
  63. Rem     tpystyne   11/07/92 -  make analyze parameters optional 
  64. Rem     mmoore     11/04/92 -  add new analyze options 
  65. Rem     ghallmar   11/03/92 -  add dbms_transaction.purge_mixed 
  66. Rem     rkooi      10/30/92 -  get rid of caller_id and unique_stmt_id 
  67. Rem     rkooi      10/26/92 -  owner -> schema for SQL2 
  68. Rem     rkooi      10/25/92 -  bug 135880 
  69. Rem     mmoore     10/13/92 - #(131686) change messages 2074,4092,0034 
  70. Rem     rkooi      10/02/92 -  compile_all fix 
  71. Rem     mmoore     10/02/92 -  change pls_integer to binary_integer 
  72. Rem     tpystyne   10/01/92 -  fix Bob's mistakes 
  73. Rem     tpystyne   09/28/92 -  disallow commit/rollback force in rpc and trigge
  74. Rem     mmoore     09/25/92 - #(130566) don't allow set_nls or set_role in trig
  75. Rem     tpystyne   09/23/92 -  rename analyze to analyze_object 
  76. Rem     rkooi      08/24/92 -  handle delimited id's in alter_compile 
  77. Rem     tpystyne   08/06/92 -  add analyze_schema 
  78. Rem     epeeler    07/29/92 -  add function to get time 
  79. Rem     rkooi      06/25/92 -  workaround pl/sql bug with 'in' in SQL
  80. Rem     rkooi      06/03/92 -  add 'get unique session id' 
  81. Rem     jcohen     05/28/92 -  add = to alter session set label 
  82. Rem     jloaiza    05/12/92 -  add discrete 
  83. Rem     rkooi      04/22/92 -  put in checks for execute_sql for triggs, stored
  84. Rem     mmoore     04/14/92 -  move begin_oltp to package transaction 
  85. Rem     rkooi      04/06/92 -  merge changes from branch 1.4.300.1 
  86. Rem     rkooi      04/01/92 -  Creation - split/recombined from other files
  87. Rem     mroberts   02/21/92 -  call alter_compile, not sql_ddl 
  88. Rem     rkooi      02/06/92 -  testing 
  89. Rem     rkooi      02/03/92 -  compilation errors 
  90. Rem     rkooi      01/16/92 -  Creation 
  91.  
  92. REM ********************************************************************
  93. REM THESE PACKAGES MUST NOT BE MODIFIED BY THE CUSTOMER.  DOING SO
  94. REM COULD CAUSE INTERNAL ERRORS AND SECURITY VIOLATIONS IN THE
  95. REM RDBMS.  SPECIFICALLY, THE PSD* AND EXECUTE_SQL ROUTINES MUST NOT BE
  96. REM CALLED DIRECTLY BY ANY CLIENT AND MUST REMAIN PRIVATE TO THE PACKAGE BODY.
  97. REM ********************************************************************
  98.  
  99. create or replace package dbms_transaction is
  100.  
  101.   ------------
  102.   --  OVERVIEW
  103.   --
  104.   --  This package provides access to SQL transaction statements from
  105.   --  stored procedures.
  106.   --  It also provids functions for monitoring transaction activities
  107.   --  (transaction ids and ordering of steps of transactions )
  108.  
  109.   ----------------------------
  110.   --  PROCEDURES AND FUNCTIONS
  111.   --
  112.   procedure read_only;
  113.   --  Equivalent to SQL "SET TRANSACTION READ ONLY"
  114.   procedure read_write;
  115.   --  Equivalent to SQL "SET TRANSACTION READ ONLY"
  116.   procedure advise_rollback;
  117.   --  Equivalent to SQL "ALTER SESSION ADVISE ROLLBACK"
  118.   procedure advise_nothing;
  119.   --  Equivalent to SQL "ALTER SESSION ADVISE NOTHING"
  120.   procedure advise_commit;
  121.   --  Equivalent to SQL "ALTER SESSION ADVISE COMMIT"
  122.   procedure use_rollback_segment(rb_name varchar2);
  123.   --  Equivalent to SQL "SET TRANSACTION USE ROLLBACK SEGMENT <rb_seg_name>"
  124.   --  Input arguments:
  125.   --    rb_name
  126.   --      Name of rollback segment to use.
  127.   procedure commit_comment(cmnt varchar2);
  128.   --  Equivalent to SQL "COMMIT COMMENT <text>"
  129.   --  Input arguments:
  130.   --    cmnt
  131.   --      Comment to assoicate with this comment.
  132.   procedure commit_force(xid varchar2, scn varchar2 default null);
  133.   --  Equivalent to SQL "COMMIT FORCE <text>, <number>"
  134.   --  Input arguments:
  135.   --    xid
  136.   --      Local or global transaction id.
  137.   --    scn
  138.   --      System change number.
  139.   procedure commit;
  140.     pragma interface (C, commit);                          -- 1 (see psdicd.c)
  141.   --  Equivalent to SQL "COMMIT".  Here for completeness.  This is
  142.   --    already implemented as part of PL/SQL.
  143.   procedure savepoint(savept varchar2);
  144.     pragma interface (C, savepoint);               -- 2 (see psdicd.c)
  145.   --  Equivalent to SQL "SAVEPOINT <savepoint_name>".  Here for
  146.   --    completeness. This is already implemented as part of PL/SQL.
  147.   --  Input arguments:
  148.   --    savept
  149.   --      Savepoint identifier.
  150.   procedure rollback;
  151.     pragma interface (C, rollback);               -- 3 (see psdicd.c)
  152.   --  Equivalent to SQL "ROLLBACK".  Here for completeness. This is 
  153.   --    already implemented as part of PL/SQL.
  154.   procedure rollback_savepoint(savept varchar2);
  155.     pragma interface (C, rollback_savepoint);           -- 4 (see psdicd.c)
  156.   --  Equivalent to SQL "ROLLBACK TO SAVEPOINT <savepoint_name>".  Here for
  157.   --    completeness. This is already implemented as part of PL/SQL.
  158.   --  Input arguments:
  159.   --    savept
  160.   --      Savepoint identifier.
  161.   procedure rollback_force(xid varchar2);
  162.   --  Equivalent to SQL "ROLLBACK FORCE <text>"
  163.   --  Input arguments:
  164.   --    xid
  165.   --      Local or global transaction id.
  166.   procedure begin_discrete_transaction;
  167.     pragma interface (C, begin_discrete_transaction);      -- 5 (see psdicd.c)
  168.   --  Set "discrete transaction mode" for this transaction.
  169.   --  Exceptions:
  170.   --    ORA-08175 will be generated if a transaction attempts an operation 
  171.   --      which cannot be performed as a discrete transaction.  If this 
  172.   --      exception is encountered, rollback and retry the transaction.
  173.  
  174.   --    ORA-08176 will be generated if a transaction encounters data changed 
  175.   --      by an operation that does not generate rollback data : create index,
  176.   --      direct load or discrete transaction.  If this exception is
  177.   --      encountered, retry the operation that received the exception.
  178.   --    
  179.   DISCRETE_TRANSACTION_FAILED exception;
  180.     pragma exception_init(DISCRETE_TRANSACTION_FAILED, -8175);
  181.  
  182.   CONSISTENT_READ_FAILURE exception;
  183.     pragma exception_init(CONSISTENT_READ_FAILURE, -8176);
  184.  
  185.   procedure purge_mixed(xid varchar2);
  186.   --  When indoubt transactions are forced to commit or rollback (instead of
  187.   --    letting automatic recovery resolve their outcomes), there is a
  188.   --    possibility that a transaction can have a mixed outcome: some sites
  189.   --    commit, and others rollback.  Such inconsistency cannot be resolved
  190.   --    automatically by ORACLE; however, ORACLE will flag entries in
  191.   --    DBA_2PC_PENDING by setting the MIXED column to a value of 'yes'.
  192.   --    ORACLE will never automatically delete information about a mixed
  193.   --    outcome transaction.  When the application or DBA is sure all
  194.   --    inconsistencies that might have arisen as a result of the mixed
  195.   --    transaction have been resolved, this procedure can be used to
  196.   --    delete the information about a given mixed outcome transaction.
  197.   --  Input arguments:
  198.   --    xid
  199.   --      This must be set to the value of the LOCAL_TRAN_ID column in 
  200.   --      the DBA_2PC_PENDING table.
  201.  
  202.   FUNCTION local_transaction_id(create_transaction BOOLEAN := FALSE)
  203.     RETURN VARCHAR2;
  204.   --  Return local (to instance) unique identfier for current transaction
  205.   --  Return null if there is no current transction.
  206.   --  Input parmaeters:
  207.   --     create_transaction 
  208.   --       If true , start a transaciton if one is not currently 
  209.   --       active.
  210.   --
  211.   FUNCTION step_id RETURN NUMBER;
  212.   --  Return local (to local transaction ) unique positive integer that orders
  213.   --  The DML operations of a transaction.
  214.   --  Input parmaeters:
  215.  
  216. end;
  217. /
  218. drop public synonym dbms_transaction
  219. /
  220. create public synonym dbms_transaction for sys.dbms_transaction
  221. /
  222. grant execute on dbms_transaction to public
  223. /
  224.  
  225. create or replace package dbms_session is
  226.   ------------
  227.   --  OVERVIEW
  228.   --
  229.   --  This package provides access to SQL "alter session" statements, and
  230.   --  other session information from, stored procedures.
  231.  
  232.   ----------------------------
  233.   --  PROCEDURES AND FUNCTIONS
  234.   --
  235.   procedure set_role(role_cmd varchar2);
  236.   --  Equivalent to SQL "SET ROLE ...".
  237.   --  Input arguments:
  238.   --    role_cmd
  239.   --      This text is appended to "set role " and then executed as SQL.
  240.   procedure set_sql_trace(sql_trace boolean);
  241.   --  Equivalent to SQL "ALTER SESSION SET SQL_TRACE ..."
  242.   --  Input arguments:
  243.   --    sql_trace
  244.   --      TRUE or FALSE.  Turns tracing on or off.
  245.   procedure set_nls(param varchar2, value varchar2);
  246.   --  Equivalent to SQL "ALTER SESSION SET <nls_parameter> = <value>"
  247.   --  Input arguments:
  248.   --    param
  249.   --      The NLS parameter. The parameter name must begin with 'NLS'.
  250.   --    value
  251.   --      The value to set the parameter to.  If the parameter is a
  252.   --      text literal then it will need embedded single-quotes.  For
  253.   --      example "set_nls('nls_date_format','''DD-MON-YY''')"
  254.   procedure close_database_link(dblink varchar2);
  255.   --  Equivalent to SQL "ALTER SESSION CLOSE DATABASE LINK <name>"
  256.   --  Input arguments:
  257.   --    name
  258.   --      The name of the database link to close.
  259.   procedure set_label(lbl varchar2);
  260.   --  Equivalent to SQL "ALTER SESSION SET LABEL <label specification>"
  261.   --  Input arguments:
  262.   --    lbl
  263.   --      Either 'DBHIGH', 'DBLOW', or a text literal.
  264.   procedure set_mls_label_format(fmt varchar2);
  265.   --  Equivalent to SQL "ALTER SESSION SET MLS_LABEL_FORMAT <format>"
  266.   --  Input arguments:
  267.   --    fmt
  268.   --      Format specification for the label.
  269.   procedure reset_package;
  270.   --  Deinstantiate all packages in this session.  In other words, free
  271.   --    all package state.  This is the situation at the beginning of
  272.   --    a session.
  273.   function unique_session_id return varchar2;
  274.   --  Return an identifier that is unique for all sessions currently
  275.   --    connected to this database.  Multiple calls to this function 
  276.   --    during the same session will always return the same result.
  277.   --  Output arguments:
  278.   --    unique_session_id
  279.   --      can return up to 24 bytes.
  280.   function is_role_enabled(rolename varchar2) return boolean;
  281.   --  Determine if the named role is enabled for this session.
  282.   --  Input arguments:
  283.   --    rolename
  284.   --      Name of the role.
  285.   --  Output arguments:
  286.   --    is_role_enabled
  287.   --      TRUE or FALSE depending on whether the role is enabled.
  288.   procedure set_close_cached_open_cursors(close_cursors boolean);
  289.   --  Equivalent to SQL "ALTER SESSION SET CLOSE_CACHED_OPEN_CURSORS ..."
  290.   --  Input arguments:
  291.   --    close_cursors
  292.   --      TRUE or FALSE.  Turns close_cached_open_cursors on or off.
  293.   procedure free_unused_user_memory;
  294.   --  Procedure for users to reclaim unused memory after performing operations
  295.   --  requiring large amounts of memory (where large is >100K).  Note that 
  296.   --  this procedure should only be used in cases where memory is at a 
  297.   --  premium.  
  298.   --
  299.   --  Examples operations using lots of memory are:
  300.   -- 
  301.   --     o  large sorts where entire sort_area_size is used and
  302.   --        sort_area_size is hundreds of KB
  303.   --     o  compiling large PL/SQL packages/procedures/functions
  304.   --     o  storing hundreds of KB of data within PL/SQL indexed tables
  305.   --
  306.   --  One can monitor user memory by tracking the statistics 
  307.   --  "session uga memory" and "session pga memory" in the 
  308.   --  v$sesstat/v$statname fixed views.  Monitoring these statistics will
  309.   --  also show how much memory this procedure has freed.
  310.   --
  311.   --  The behavior of this procedure depends upon the configuration of the 
  312.   --  server operating on behalf of the client:
  313.   --  
  314.   --     o  dedicated server - returns unused PGA memory to the OS
  315.   --     o  MTS server       - returns unused session memory to the shared_pool
  316.   --  
  317.   --  In order to free memory using this procedure, the memory must 
  318.   --  not be in use.  
  319.   -- 
  320.   --  Once an operation allocates memory, only the same type of operation can 
  321.   --  reuse the allocated memory.  For example, once memory is allocated 
  322.   --  for sort, even if the sort is complete and the memory is no longer 
  323.   --  in use, only another sort can reuse the sort-allocated memory.  For
  324.   --  both sort and compilation, after the operation is complete, the memory
  325.   --  is no longer in use and the user can invoke this procedure to free the
  326.   --  unused memory. 
  327.   --
  328.   --  An indexed table implicitly allocates memory to store values assigned
  329.   --  to the indexed table's elements.  Thus, the more elements in an indexed 
  330.   --  table, the more memory the RDBMS allocates to the indexed table.  As 
  331.   --  long as there are elements within the indexed table, the memory
  332.   --  associated with an indexed table is in use. 
  333.   -- 
  334.   --  The scope of indexed tables determines how long their memory is in use. 
  335.   --  Indexed tables declared globally are indexed tables declared in packages
  336.   --  or package bodies.  They allocate memory from session memory.  For an
  337.   --  indexed table declared globally, the memory will remain in use
  338.   --  for the lifetime of a user's login (lifetime of a user's session),
  339.   --  and is freed after the user disconnects from ORACLE.
  340.   --     
  341.   --  Indexed tables declared locally are indexed tables declared within
  342.   --  functions, procedures, or anonymous blocks.  These indexed tables
  343.   --  allocate memory from PGA memory.  For an indexed table declared 
  344.   --  locally, the memory will remain in use for as long as the user is still
  345.   --  executing the procedure, function, or anonymous block in which the 
  346.   --  indexed table is declared.  After the procedure, function, or anonymous
  347.   --  block is finished executing, the memory is then available for other 
  348.   --  locally declared indexed tables to use (i.e., the memory is no longer
  349.   --  in use).
  350.   --  
  351.   --  Assigning an uninitialized, "empty," indexed table to an existing index
  352.   --  table is a method to explicitly re-initialize the indexed table and the
  353.   --  memory associated with the indexed table.  After this operation,
  354.   --  the memory associated with the indexed table will no longer be in use, 
  355.   --  making it available to be freed by calling this procedure.  This method
  356.   --  is particularly useful on indexed tables declared globally which can grow
  357.   --  during the lifetime of a user's session, as long as the user no 
  358.   --  longer needs the contents of the indexed table.  
  359.   --  
  360.   --  The memory rules associated with an indexed table's scope still apply; 
  361.   --  this method and this procedure, however, allow users to 
  362.   --  intervene and to explictly free the memory associated with an
  363.   --  indexed table. 
  364.   -- 
  365.   --  The PL/SQL fragment below illustrates the method and the use 
  366.   --  of procedure free_unused_user_memory.
  367.   --
  368.   --  create package foobar
  369.   --     type number_idx_tbl is table of number indexed by binary_integer;
  370.   -- 
  371.   --     store1_table  number_idx_tbl;     --  PL/SQL indexed table
  372.   --     store2_table  number_idx_tbl;     --  PL/SQL indexed table
  373.   --     store3_table  number_idx_tbl;     --  PL/SQL indexed table
  374.   --     ...
  375.   --  end;            --  end of foobar
  376.   --
  377.   --  declare
  378.   --     ...
  379.   --     empty_table   number_idx_tbl;     --  uninitialized ("empty") version
  380.   --  
  381.   --  begin
  382.   --     for i in 1..1000000 loop
  383.   --       store1_table(i) := i;           --  load data
  384.   --     end loop;
  385.   --     ...
  386.   --     store1_table := empty_table;      --  "truncate" the indexed table
  387.   --     ... 
  388.   --     -
  389.   --     dbms_session.free_unused_user_memory;  -- give memory back to system
  390.   --  
  391.   --     store1_table(1) := 100;           --  index tables still declared;
  392.   --     store2_table(2) := 200;           --  but truncated.
  393.   --     ...
  394.   --  end;
  395.   -- 
  396.   --  Performance Implication: 
  397.   --     This routine should be used infrequently and judiciously.
  398.   --       
  399.   --  Input arguments:
  400.   --     n/a
  401. end;
  402. /
  403.  
  404. drop public synonym dbms_session
  405. /
  406. create public synonym dbms_session for sys.dbms_session
  407. /
  408. grant execute on dbms_session to public
  409. /
  410.  
  411. create or replace package dbms_ddl is
  412.   ------------
  413.   --  OVERVIEW
  414.   --
  415.   --  This package provides access to some SQL DDL statements from
  416.   --  stored procedures.
  417.  
  418.   ----------------------------
  419.   --  PROCEDURES AND FUNCTIONS
  420.   --
  421.   procedure alter_compile(type varchar2, schema varchar2, name varchar2);
  422.   --  Equivalent to SQL "ALTER PROCEDURE|FUNCTION|PACKAGE [<schema>.]
  423.   --    <name> COMPILE [BODY]".  If the named object is this package,
  424.   --    or any packages upon which it depends (currently "standard" or 
  425.   --    "dbms_standard") then the procedure simply returns (since these
  426.   --    packages are clearly successfully compiled).
  427.   --  Input arguments:
  428.   --    type
  429.   --      Must be one of "PROCEDURE", "FUNCTION", "PACKAGE" or "PACKAGE
  430.   --      BODY".
  431.   --    schema
  432.   --      The schema name.  If NULL then use current schema.  Case sensitive.
  433.   --    name
  434.   --      The name of the object.  Case sensitive.
  435.   --  Exceptions:
  436.   --    ORA-20000: Insufficient privileges or object does not exist.
  437.   --    ORA-20001: Remote object, cannot compile.
  438.   --    ORA-20002: Bad value for object type.  Should be one of PACKAGE,
  439.   --      PACKAGE BODY, PROCEDURE, or FUNCTION.
  440.   procedure analyze_object
  441.     (type varchar2, schema varchar2, name varchar2, method varchar2,
  442.      estimate_rows number default null, 
  443.      estimate_percent number default null);
  444.   --  Equivalent to SQL "ANALYZE TABLE|CLUSTER|INDEX [<schema>.]<name>
  445.   --    [<method>] STATISTICS [SAMPLE <n> [ROWS|PERCENT]]"
  446.   --  Input arguments:
  447.   --    type
  448.   --      One of 'TABLE', 'CLUSTER' or 'INDEX'.  If none of these, the
  449.   --      procedure just returns.
  450.   --    schema
  451.   --      schema of object to analyze.  NULL means current schema.  Case
  452.   --      sensitive.
  453.   --    name
  454.   --      name of object to analyze.  Case sensitive.
  455.   --    method
  456.   --      NULL or 'ESTIMATE'.  If 'ESTIMATE' then either estimate_rows
  457.   --      or estimate_percent must be non-zero.
  458.   --    estimate_rows
  459.   --      Number of rows to estimate
  460.   --    estimate_percent
  461.   --      Percentage of rows to estimate.  If estimate_rows is specified
  462.   --      than ignore this parameter.
  463.   --  Exceptions:
  464.   --    ORA-20000: Insufficient privileges or object does not exist.
  465.   --    ORA-20001: Bad value for object type.  Should be one of TABLE, INDEX
  466.   --      or CLUSTER.
  467. end;
  468. /
  469.  
  470. drop public synonym dbms_ddl
  471. /
  472. create public synonym dbms_ddl for sys.dbms_ddl
  473. /
  474. grant execute on dbms_ddl to public
  475. /
  476.  
  477. create or replace package dbms_utility is
  478.   ------------
  479.   --  OVERVIEW
  480.   --
  481.   --  This package provides various utility routines.
  482.  
  483.   ----------------------------
  484.   --  PL/SQL TABLES
  485.   --
  486.   type uncl_array IS table of VARCHAR2(227) index by BINARY_INTEGER;
  487.   --  Lists of "USER"."NAME"."COLUMN"@LINK should be stored here
  488.  
  489.   type name_array IS table of VARCHAR2(30) index by BINARY_INTEGER;
  490.   --  Lists of NAME should be stored here
  491.  
  492.   type dblink_array IS table of VARCHAR2(128) index by BINARY_INTEGER;
  493.   --  Lists of database links should be stored here
  494.  
  495.   ----------------------------
  496.   --  PROCEDURES AND FUNCTIONS
  497.   --
  498.   procedure compile_schema(schema varchar2);
  499.   --  Compile all procedures, functions and packages in the specified
  500.   --  schema.  After calling this procedure you should select from view
  501.   --  ALL_OBJECTS for items with status of 'INVALID' to see if all objects
  502.   --  were successfully compiled.  You may use the SQLDBA command "SHOW
  503.   --  ERRORS <type> <schema>.<name>" to see the errors assocated with
  504.   --  'INVALID' objects.
  505.   --  Input arguments:
  506.   --    schema
  507.   --      Name of the schema.
  508.   --  Exceptions:
  509.   --    ORA-20000: Insufficient privileges for some object in this schema.
  510.   procedure analyze_schema(schema varchar2, method varchar2, 
  511.     estimate_rows number default null, 
  512.     estimate_percent number default null);
  513.   --  Analyze all the tables, clusters and indexes in a schema.
  514.   --  Input arguments:
  515.   --    schema
  516.   --      Name of the schema.
  517.   --    method, estimate_rows, estimate_ercent
  518.   --      See the descriptions above in sql_ddl.analyze.object.
  519.   --  Exceptions:
  520.   --    ORA-20000: Insufficient privileges for some object in this schema.
  521.   function format_error_stack return varchar2;
  522.     pragma interface (C, format_error_stack);            -- 1 (see psdicd.c)
  523.   --  Format the current error stack.  This can be used in exception
  524.   --    handlers to look at the full error stack.
  525.   --  Output arguments:
  526.   --    format_error_stack
  527.   --      Returns the error stack.  May be up to 2000 bytes.
  528.   function format_call_stack return varchar2;
  529.     pragma interface (C, format_call_stack);            -- 2 (see psdicd.c)
  530.   --  Format the current call stack.  This can be used an any stored
  531.   --    procedure or trigger to access the call stack.  This can be
  532.   --    useful for debugging.
  533.   --  Output arguments:
  534.   --    format_call_stack
  535.   --      Returns the call stack.  May be up to 2000 bytes.
  536.   function is_parallel_server return boolean;
  537.   --  Find out if this database is running in parallel server mode.
  538.   --  Output arguments:
  539.   --    is_parallel_server
  540.   --      TRUE if this instance was started in parallel server mode,
  541.   --      FALSE otherwise.
  542.   function get_time return number;
  543.   --  Find out the current time in 100th's of a second.
  544.   --  Output argukments:
  545.   --    get_time
  546.   --      The time is the number of 100th's of a second from some
  547.   --      arbitrary epoch.
  548.   procedure name_resolve(name in varchar2, context in number,
  549.     schema out varchar2, part1 out varchar2, part2 out varchar2,
  550.     dblink out varchar2, part1_type out number, object_number out number);
  551.   --  Resolve the given name.  Do synonym translation if necessary.  Do
  552.   --    authorization checking.
  553.   --  Input arguments:
  554.   --    name
  555.   --      The name of the object.  This can be of the form [[a.]b.]c[@d]
  556.   --      where a,b,c are SQL identifier and d is a dblink.  No syntax
  557.   --      checking is performed on the dblink.  If a dblink is specified,
  558.   --      of the name resolves to something with a dblink, then object
  559.   --      is not resolved, but the schema, part1, part2 and dblink out
  560.   --      arguments are filled in.  a,b and c may be delimted identifiers,
  561.   --      and may contain NLS characters (single and multi-byte).
  562.   --    context
  563.   --      Not currently used, must be set to 1 for future compatibility.
  564.   --  Output arguments:
  565.   --    schema
  566.   --      The schema of the object.  If no schema is specified in 'name'
  567.   --      then the schema is determined by resolving the name.
  568.   --    part1
  569.   --      The first part of the name.  The type of this name is specified
  570.   --      part1_type (synonym, procedure or package).
  571.   --    part2
  572.   --      If this is non-null, then this is a procedure name within the
  573.   --      package indicated by part1.
  574.   --    dblink
  575.   --      If this is non-null then a database link was either specified
  576.   --      as part of 'name' or 'name' was a synonym which resolved to
  577.   --      something with a database link.  In this later case, part1_type
  578.   --      will indicate a synonym.
  579.   --    part1_type
  580.   --      The type of part1 is
  581.   --        5 - synonym
  582.   --        7 - procedure (top level)
  583.   --        8 - function (top level)
  584.   --        9 - package
  585.   --      If a synonym, it means that 'name' is a synonym that translats
  586.   --      to something with a database link.  In this case, if further
  587.   --      name translation is desired, then you must call the 
  588.   --      dbms_utility.name_resolve procedure on this remote node.
  589.   --    object_number
  590.   --      If non-null then 'name' was successfully resolved and this is the
  591.   --      object number which it resolved to.
  592.   --  Exceptions:
  593.   --    All errors are handled by raising exceptions.  A wide variety of
  594.   --    exceptions are possible, based on the various syntax error that
  595.   --    are possible when specifying object names.
  596.   procedure name_tokenize( name    in  varchar2,
  597.                    a       out varchar2,
  598.                    b       out varchar2,
  599.                        c       out varchar2,
  600.                    dblink  out varchar2, 
  601.                            nextpos out binary_integer);
  602.   --  Call the parser to parse the given name as "a [. b [. c ]][@ dblink ]".
  603.   --  Strip doublequotes, or convert to uppercase if there are no quotes.
  604.   --    Ignore comments of all sorts.  Do no semantic analysis.  Leave any
  605.   --      missing values as null. 
  606.   --  For each of a,b,c,dblink, tell where the following token starts
  607.   --    in anext,bnext,cnext,dnext respectively.
  608.   PROCEDURE comma_to_table( list   IN  VARCHAR2,
  609.                             tablen OUT BINARY_INTEGER,
  610.                             tab    OUT uncl_array);
  611.   --  Convert a comma-separated list of names into a PL/SQL table of names
  612.   --  This uses name_tokenize to figure out what are names and what are commas
  613.  
  614.   PROCEDURE table_to_comma( tab    IN  uncl_array, 
  615.                             tablen OUT BINARY_INTEGER,
  616.                             list   OUT VARCHAR2);
  617.   --  Convert a PL/SQL table of names into a comma-separated list of names
  618.  
  619.   FUNCTION port_string RETURN VARCHAR2;
  620.   --  Return a string that uniquely identifies the version of Oracle and 
  621.   --  the port (operating system).  EG "VAX/VMX-7.1.0.0"
  622.   --  maximum length is port specific.
  623.  
  624.   function make_data_block_address(file number, block number) return number;
  625.   --  Creates a data block address given a file# and a block#.  A data block
  626.   --  address is the internal structure used to identify a block in the
  627.   --  database.  This is function useful when accessing certain fixed tables
  628.   --  that contain data block addresses.
  629.   --  Input arguments:
  630.   --    file  - the file that contains the block
  631.   --    block - the offset of the block within the file in terms of block 
  632.   --            increments
  633.   --  Output arguments:
  634.   --    dba   - the data block address
  635.   function data_block_address_file(dba number) return number;
  636.   --  Get the file number part of a data block address
  637.   --  Input arguments:
  638.   --    dba   - a data block address
  639.   --  Output Arguments:
  640.   --    file  - the file that contains the block
  641.   function data_block_address_block(dba number) return number;
  642.   --  Get the block number part of a data block address
  643.   --  Input arguments:
  644.   --    dba   - a data block address
  645.   --  Output Arguments:
  646.   --    block  - the block offset of the block  
  647. end;
  648. /
  649.  
  650. drop public synonym dbms_utility
  651. /
  652. create public synonym dbms_utility for sys.dbms_utility
  653. /
  654. grant execute on dbms_utility to public
  655. /
  656.  
  657.  
  658.   ------------
  659.   --  OVERVIEW
  660.   --
  661.   --  The dbms_application_info package provides a mechanism for registering 
  662.   --  the name of the application module that is currently running with the 
  663.   --  rdbms. Registering the name of the module allows DBAs to monitor how the 
  664.   --  system is being used, and do performance analysis, and resource 
  665.   --  accounting by module.  The name that is registered through this 
  666.   --  package will appear in the 'module' and 'action' column of 
  667.   --  the v$session virtual table. It will also appear in the 'module' and 
  668.   --  'action' columns in v$sqlarea.
  669.   --
  670.   --  The MODULE name is normally set to a user recognizable name for the 
  671.   --  program that is currently executing.  For example, this could be the name
  672.   --  of the form that is executing, or it could be the name of the script that
  673.   --  is being executed by sql*plus.  The idea is to be able to identify the
  674.   --  high level function that is being performed.  For instance, you can tell
  675.   --  that a user is in the 'order entry' form instead of just telling that he
  676.   --  is running sql*forms.  We encourage application tool vendors to 
  677.   --  automatically set this value whenever an application is executed.
  678.   --
  679.   --  The ACTION name is normally set to a specific action that a user is
  680.   --  performing within a module.  For instance a user could be 'reading
  681.   --  mail' or 'entering a new customer'.  This is meant to more specifically 
  682.   --  identify what a user is currently doing.  The action should normally be
  683.   --  set by the designer of a specific application.  It should not 
  684.   --  automatically be set by the application tool.
  685.   --
  686.   --  If the local DBA would like to gather his own statistics based on
  687.   --  module, then the DBA can implement a wrapper around this package 
  688.   --  by writing a version of this package in another schema that first 
  689.   --  gathers statistics and then calls the sys version of the package.  The 
  690.   --  public synonym for dbms_application_info can then be changed to point 
  691.   --  to the DBA's version of the package.
  692.   --
  693. create or replace package dbms_application_info is
  694.   ----------------------------
  695.   --  PROCEDURES AND FUNCTIONS
  696.   --
  697.   procedure set_module(module_name varchar2, action_name varchar2);
  698.   --  Sets the name of the module that is currently running to a new
  699.   --    module.  When the current module terminates, this should
  700.   --    be called with the name of the new module if there is one, or
  701.   --    null if there is not a new module.  Passing null for either of these
  702.   --    values is equivalent to passing a zero length string.
  703.   --  Input arguments:
  704.   --    module_name
  705.   --      The name of the module that will now be running.  The maximum
  706.   --      length of the module name is 48 bytes.  Longer names will be
  707.   --      truncated.
  708.   --    action_name
  709.   --      The name of the action that will now be running.  The maximum
  710.   --      length of the action_name is 32 bytes.  Longer names will be
  711.   --      truncated. If the action name is not being specified, then null 
  712.   --      should be passed for this value.
  713.   --
  714.   procedure set_action(action_name varchar2);
  715.   --  Sets the name of the current action within the current module.
  716.   --    When the current action terminates, this should be called with the 
  717.   --    name of the new action if there is one, or null if there is not a 
  718.   --    new action.  Passing null for this value is equivalent to passing
  719.   --    a zero length string.
  720.   --  Input arguments:
  721.   --    action_name
  722.   --      The name of the action that will now be running.  The maximum
  723.   --      length of the action_name is 32 bytes.  Longer names will be
  724.   --      truncated.
  725.   --
  726.   procedure read_module(module_name out varchar2, action_name out varchar2);
  727.   --  Reads the values of the module and action fields of the current 
  728.   --    session.
  729.   --  Output arguments:
  730.   --    module_name 
  731.   --      The last value that the module name was set to using the set_module
  732.   --      procedure.
  733.   --    action_name
  734.   --      The last value that the action name was set to using the set_module
  735.   --      or set_action procedures.
  736.   --
  737.   procedure set_client_info(client_info varchar2);
  738.   --  Sets the client info field of the session.  The client info field is
  739.   --    provided for the use of individual applications.  The Oracle system 
  740.   --    does not use this field for any purpose.  After being set, the 
  741.   --    client info field can be queried from v$session.
  742.   --  Input arguments:
  743.   --    client_info 
  744.   --      Any character data that the client wishes to store up to a maximum of
  745.   --      64 bytes.  Longer values will be truncated.  Passing a null is
  746.   --      equivalent to passing a zero length string.
  747.  
  748.   procedure read_client_info(client_info out varchar2);
  749.   --  Reads the value of the client_info field of the current session.
  750.   --  Output arguments:
  751.   --    client_info
  752.   --      The last value that the client_info field was set to using the
  753.   --      set_client_info procedure.
  754.  
  755. end;
  756. /
  757.  
  758. -- Note that the public synonym for dbms_application_info is not dropped before
  759. -- creation in order to allow users to redirect the public synonym to point
  760. -- to their own package.  If we dropped it, then everytime they ran this 
  761. -- script, their package would be overriden by the default oracle package.
  762. create public synonym dbms_application_info for sys.dbms_application_info
  763. /
  764. grant execute on sys.dbms_application_info to public
  765. /
  766.  
  767.  
  768. create or replace package dbms_system is
  769.   ------------
  770.   --  OVERVIEW
  771.   --
  772.   --  This package provides some system level utilities.
  773.  
  774.   --  SECURITY
  775.   --
  776.   --  This package is only accessible to user SYS by default.  You can control
  777.   --  access to these routines by only granting execute to privileged users.
  778.  
  779.   ----------------------------
  780.   --  PROCEDURES AND FUNCTIONS
  781.   --
  782.   procedure set_ev(si binary_integer, se binary_integer, 
  783.                ev binary_integer, le binary_integer, nm varchar2);
  784.   --  This is an internally used routine that should never be called by users.
  785.  
  786.   procedure read_ev(iev binary_integer, oev out binary_integer);
  787.   --  This is an internally used routine that should never be called by users.
  788.   --
  789.   --
  790.   procedure set_sql_trace_in_session(sid number, serial# number, 
  791.                                  sql_trace boolean);
  792.   --  Enable sql_trace in the session identified by (sid, serial#).  These
  793.   --  value are gotten from v$session. 
  794.   --  Input arguments:
  795.   --   sid  
  796.   --      session id
  797.   --   serial#
  798.   --      session serial number
  799.   --  sql_trace
  800.   --      if true then enable tracing, if false disable tracing.    
  801.   --
  802. end;
  803. /
  804.  
  805. create or replace package dbms_space is
  806.   ------------
  807.   --  OVERVIEW
  808.   --
  809.   --  This package provides segment space information not currently
  810.   --  available through the standard views.
  811.  
  812.   --  SECURITY
  813.   --
  814.   --  The execution privilege is granted to PUBLIC. Procedures in this
  815.   --  package run under the caller security. The user must have ANALYZE
  816.   --  privilege on the object.
  817.  
  818.  
  819.   ----------------------------
  820.  
  821.   ----------------------------
  822.   --  PROCEDURES AND FUNCTIONS
  823.   --
  824.   procedure unused_space(segment_owner IN varchar2, 
  825.                          segment_name IN varchar2,
  826.                          segment_type IN varchar2,
  827.                          total_blocks OUT number,
  828.                          total_bytes OUT number,
  829.                          unused_blocks OUT number,
  830.                          unused_bytes OUT number,
  831.                          last_used_extent_file_id OUT number,
  832.                          last_used_extent_block_id OUT number,
  833.                          last_used_block OUT number
  834.                          );
  835.   --  Returns information about unused space in an object (table, index,
  836.   --    or cluster).
  837.   --  Input arguments:
  838.   --   segment_owner  
  839.   --      schema name of the segment to be analyzed
  840.   --   segment_name  
  841.   --      object name of the segment to be analyzed
  842.   --   segment_type  
  843.   --      type of the segment to be analyzed (TABLE, INDEX, or CLUSTER)
  844.   --  Output arguments:
  845.   --   total_blocks  
  846.   --      total number of blocks in the segment
  847.   --   total_bytes  
  848.   --      the same as above, expressed in bytes
  849.   --   unused_blocks  
  850.   --      number of blocks which are not used 
  851.   --   unused_bytes  
  852.   --      the same as above, expressed in bytes
  853.   --   last_used_extent_file_id 
  854.   --      the file ID of the last extent which contains data
  855.   --   last_used_extent_block_id 
  856.   --      the block ID of the last extent which contains data
  857.   --   last_used_block  
  858.   --      the last block within this extent which contains data
  859.   procedure free_blocks (segment_owner IN varchar2, 
  860.                          segment_name IN varchar2,
  861.                          segment_type IN varchar2,
  862.                          freelist_group_id IN number,
  863.                          free_blks OUT number,
  864.                          scan_limit IN number DEFAULT NULL
  865.                          );
  866.   --  Returns information about free blocks in an object (table, index,
  867.   --    or cluster).
  868.   --  Input arguments:
  869.   --   segment_owner  
  870.   --      schema name of the segment to be analyzed
  871.   --   segment_name  
  872.   --      name of the segment to be analyzed
  873.   --   segment_type  
  874.   --      type of the segment to be analyzed (TABLE, INDEX, or CLUSTER)
  875.   --   freelist_group_id  
  876.   --      freelist group (instance) whose free list size is to be computed
  877.   --   scan_limit (optional)
  878.   --      maximum number of free blocks to read
  879.   --  Output arguments:
  880.   --   free_blks  
  881.   --      count of free blocks for the specified group
  882. end;
  883. /
  884. drop public synonym dbms_space
  885. /
  886. create public synonym dbms_space for sys.dbms_space
  887. /
  888. grant execute on dbms_space to public
  889. /
  890.